package org.hhchat.leetcode.string;

import java.util.HashMap;

/**
 * Created this one by HMH on 2017/10/2.
 */
public class code383_easy {

    static class Solution {
        public boolean canConstruct(String ransomNote, String magazine) {
            HashMap<Character, Integer> map = new HashMap<>();
            for (char c : magazine.toCharArray()) {
                map.put(c, map.getOrDefault(c, 0) + 1);
            }
            for (char c : ransomNote.toCharArray()) {
                if (map.get(c) == null) {
                    return false;
                }
                if (map.get(c) == 0) {
                    return false;
                }
                map.put(c, map.get(c) - 1);
            }
            return true;
        }
    }

    public static void main(String[] args){

    }

}
